package rdw.robot;

import java.awt.event.KeyEvent;
import java.util.HashMap;

/**
 * Maps characters to KeyStroke objects, containing the keycode and modifier key.
 */
public class KeyMapping
{
    private static final int SHIFT = KeyEvent.SHIFT_MASK;

    private static HashMap<Character, KeyStroke> CharacterMap;
    
    static
    {
    	CharacterMap = new HashMap<Character, KeyStroke>();
   		CharacterMap.put(new Character(' '), new KeyStroke(' ', KeyEvent.VK_SPACE, 0));
        CharacterMap.put(new Character('\n'), new KeyStroke('\n', KeyEvent.VK_ENTER, 0));
        CharacterMap.put(new Character('\r'), new KeyStroke('\r', KeyEvent.VK_ENTER, 0));
        CharacterMap.put(new Character('\b'), new KeyStroke('\b', KeyEvent.VK_BACK_SPACE, 0));
        CharacterMap.put(new Character('\t'), new KeyStroke('\t', KeyEvent.VK_TAB, 0));

        CharacterMap.put(new Character('a'), new KeyStroke('a', KeyEvent.VK_A, 0));
        CharacterMap.put(new Character('b'), new KeyStroke('b', KeyEvent.VK_B, 0));
        CharacterMap.put(new Character('c'), new KeyStroke('c', KeyEvent.VK_C, 0));
        CharacterMap.put(new Character('d'), new KeyStroke('d', KeyEvent.VK_D, 0));
        CharacterMap.put(new Character('e'), new KeyStroke('e', KeyEvent.VK_E, 0));
        CharacterMap.put(new Character('f'), new KeyStroke('f', KeyEvent.VK_F, 0));
        CharacterMap.put(new Character('g'), new KeyStroke('g', KeyEvent.VK_G, 0));
        CharacterMap.put(new Character('h'), new KeyStroke('h', KeyEvent.VK_H, 0));
        CharacterMap.put(new Character('i'), new KeyStroke('i', KeyEvent.VK_I, 0));
        CharacterMap.put(new Character('j'), new KeyStroke('j', KeyEvent.VK_J, 0));
        CharacterMap.put(new Character('k'), new KeyStroke('k', KeyEvent.VK_K, 0));
        CharacterMap.put(new Character('l'), new KeyStroke('l', KeyEvent.VK_L, 0));
        CharacterMap.put(new Character('m'), new KeyStroke('m', KeyEvent.VK_M, 0));
        CharacterMap.put(new Character('n'), new KeyStroke('n', KeyEvent.VK_N, 0));
        CharacterMap.put(new Character('o'), new KeyStroke('o', KeyEvent.VK_O, 0));
        CharacterMap.put(new Character('p'), new KeyStroke('p', KeyEvent.VK_P, 0));
        CharacterMap.put(new Character('q'), new KeyStroke('q', KeyEvent.VK_Q, 0));
        CharacterMap.put(new Character('r'), new KeyStroke('r', KeyEvent.VK_R, 0));
        CharacterMap.put(new Character('s'), new KeyStroke('s', KeyEvent.VK_S, 0));
        CharacterMap.put(new Character('t'), new KeyStroke('t', KeyEvent.VK_T, 0));
        CharacterMap.put(new Character('u'), new KeyStroke('u', KeyEvent.VK_U, 0));
        CharacterMap.put(new Character('v'), new KeyStroke('v', KeyEvent.VK_V, 0));
        CharacterMap.put(new Character('w'), new KeyStroke('w', KeyEvent.VK_W, 0));
        CharacterMap.put(new Character('x'), new KeyStroke('x', KeyEvent.VK_X, 0));
        CharacterMap.put(new Character('y'), new KeyStroke('y', KeyEvent.VK_Y, 0));
        CharacterMap.put(new Character('z'), new KeyStroke('z', KeyEvent.VK_Z, 0));
        
        CharacterMap.put(new Character('A'), new KeyStroke('A', KeyEvent.VK_A, SHIFT));
        CharacterMap.put(new Character('B'), new KeyStroke('B', KeyEvent.VK_B, SHIFT));
        CharacterMap.put(new Character('C'), new KeyStroke('C', KeyEvent.VK_C, SHIFT));
        CharacterMap.put(new Character('D'), new KeyStroke('D', KeyEvent.VK_D, SHIFT));
        CharacterMap.put(new Character('E'), new KeyStroke('E', KeyEvent.VK_E, SHIFT));
        CharacterMap.put(new Character('F'), new KeyStroke('F', KeyEvent.VK_F, SHIFT));
        CharacterMap.put(new Character('G'), new KeyStroke('G', KeyEvent.VK_G, SHIFT));
        CharacterMap.put(new Character('H'), new KeyStroke('H', KeyEvent.VK_H, SHIFT));
        CharacterMap.put(new Character('I'), new KeyStroke('I', KeyEvent.VK_I, SHIFT));
        CharacterMap.put(new Character('J'), new KeyStroke('J', KeyEvent.VK_J, SHIFT));
        CharacterMap.put(new Character('K'), new KeyStroke('K', KeyEvent.VK_K, SHIFT));
        CharacterMap.put(new Character('L'), new KeyStroke('L', KeyEvent.VK_L, SHIFT));
        CharacterMap.put(new Character('M'), new KeyStroke('M', KeyEvent.VK_M, SHIFT));
        CharacterMap.put(new Character('N'), new KeyStroke('N', KeyEvent.VK_N, SHIFT));
        CharacterMap.put(new Character('O'), new KeyStroke('O', KeyEvent.VK_O, SHIFT));
        CharacterMap.put(new Character('P'), new KeyStroke('P', KeyEvent.VK_P, SHIFT));
        CharacterMap.put(new Character('Q'), new KeyStroke('Q', KeyEvent.VK_Q, SHIFT));
        CharacterMap.put(new Character('R'), new KeyStroke('R', KeyEvent.VK_R, SHIFT));
        CharacterMap.put(new Character('S'), new KeyStroke('S', KeyEvent.VK_S, SHIFT));
        CharacterMap.put(new Character('T'), new KeyStroke('T', KeyEvent.VK_T, SHIFT));
        CharacterMap.put(new Character('U'), new KeyStroke('U', KeyEvent.VK_U, SHIFT));
        CharacterMap.put(new Character('V'), new KeyStroke('V', KeyEvent.VK_V, SHIFT));
        CharacterMap.put(new Character('W'), new KeyStroke('W', KeyEvent.VK_W, SHIFT));
        CharacterMap.put(new Character('X'), new KeyStroke('X', KeyEvent.VK_X, SHIFT));
        CharacterMap.put(new Character('Y'), new KeyStroke('Y', KeyEvent.VK_Y, SHIFT));
        CharacterMap.put(new Character('Z'), new KeyStroke('Z', KeyEvent.VK_Z, SHIFT));

        CharacterMap.put(new Character('0'), new KeyStroke('0', KeyEvent.VK_0, 0));
        CharacterMap.put(new Character('1'), new KeyStroke('1', KeyEvent.VK_1, 0));
        CharacterMap.put(new Character('2'), new KeyStroke('2', KeyEvent.VK_2, 0));
        CharacterMap.put(new Character('3'), new KeyStroke('3', KeyEvent.VK_3, 0));
        CharacterMap.put(new Character('4'), new KeyStroke('4', KeyEvent.VK_4, 0));
        CharacterMap.put(new Character('5'), new KeyStroke('5', KeyEvent.VK_5, 0));
        CharacterMap.put(new Character('6'), new KeyStroke('6', KeyEvent.VK_6, 0));
        CharacterMap.put(new Character('7'), new KeyStroke('7', KeyEvent.VK_7, 0));
        CharacterMap.put(new Character('8'), new KeyStroke('8', KeyEvent.VK_8, 0));
        CharacterMap.put(new Character('9'), new KeyStroke('9', KeyEvent.VK_9, 0));

        CharacterMap.put(new Character(')'), new KeyStroke(')', KeyEvent.VK_0, SHIFT));
        CharacterMap.put(new Character('!'), new KeyStroke('!', KeyEvent.VK_1, SHIFT));
        CharacterMap.put(new Character('@'), new KeyStroke('@', KeyEvent.VK_2, SHIFT));
        CharacterMap.put(new Character('#'), new KeyStroke('#', KeyEvent.VK_3, SHIFT));
        CharacterMap.put(new Character('$'), new KeyStroke('$', KeyEvent.VK_4, SHIFT));
        CharacterMap.put(new Character('%'), new KeyStroke('%', KeyEvent.VK_5, SHIFT));
        CharacterMap.put(new Character('^'), new KeyStroke('^', KeyEvent.VK_6, SHIFT));
        CharacterMap.put(new Character('&'), new KeyStroke('&', KeyEvent.VK_7, SHIFT));
        CharacterMap.put(new Character('*'), new KeyStroke('*', KeyEvent.VK_8, SHIFT));
        CharacterMap.put(new Character('('), new KeyStroke('(', KeyEvent.VK_9, SHIFT));
        CharacterMap.put(new Character('`'), new KeyStroke('`', KeyEvent.VK_BACK_QUOTE, 0));
        CharacterMap.put(new Character('~'), new KeyStroke('~', KeyEvent.VK_BACK_QUOTE, SHIFT));
        CharacterMap.put(new Character('-'), new KeyStroke('-', KeyEvent.VK_MINUS, 0));
        CharacterMap.put(new Character('_'), new KeyStroke('_', KeyEvent.VK_MINUS, SHIFT));
        CharacterMap.put(new Character('='), new KeyStroke('=', KeyEvent.VK_EQUALS, 0));
        CharacterMap.put(new Character('+'), new KeyStroke('+', KeyEvent.VK_EQUALS, SHIFT));
        CharacterMap.put(new Character('['), new KeyStroke('[', KeyEvent.VK_OPEN_BRACKET, 0));
        CharacterMap.put(new Character(']'), new KeyStroke(']', KeyEvent.VK_CLOSE_BRACKET, 0));
        CharacterMap.put(new Character('\\'), new KeyStroke('\\', KeyEvent.VK_BACK_SLASH, 0));
        CharacterMap.put(new Character('{'), new KeyStroke('{', KeyEvent.VK_OPEN_BRACKET, SHIFT));
        CharacterMap.put(new Character('}'), new KeyStroke('}', KeyEvent.VK_CLOSE_BRACKET, SHIFT));
        CharacterMap.put(new Character('|'), new KeyStroke('|', KeyEvent.VK_BACK_SLASH, SHIFT));
        CharacterMap.put(new Character(';'), new KeyStroke(';', KeyEvent.VK_SEMICOLON, 0));
        CharacterMap.put(new Character(':'), new KeyStroke(':', KeyEvent.VK_SEMICOLON, SHIFT));
        CharacterMap.put(new Character('\''), new KeyStroke('\'', KeyEvent.VK_QUOTE, 0));
        CharacterMap.put(new Character('"'), new KeyStroke('"', KeyEvent.VK_QUOTE, SHIFT));
        CharacterMap.put(new Character(','), new KeyStroke(',', KeyEvent.VK_COMMA, 0));
        CharacterMap.put(new Character('<'), new KeyStroke('<', KeyEvent.VK_COMMA, SHIFT));
        CharacterMap.put(new Character('.'), new KeyStroke('.', KeyEvent.VK_PERIOD, 0));
        CharacterMap.put(new Character('>'), new KeyStroke('>', KeyEvent.VK_PERIOD, SHIFT));
        CharacterMap.put(new Character('/'), new KeyStroke('/', KeyEvent.VK_SLASH, 0));
        CharacterMap.put(new Character('?'), new KeyStroke('?', KeyEvent.VK_SLASH, SHIFT));
    }

    public static KeyStroke getKeyStroke(char c)
    {
    	System.out.println("getting c=" + c);
    	return CharacterMap.get(new Character(c));
    }
}
